// Copyright 2012 Sergio, Raul, Dorival. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// STL
#include <iostream>
#include <cmath>

// GemLab
#include "gemlab.h"

using std::cout;
using std::endl;
using GemLab::Array;
using GemLab::String;

int main(int argc, char **argv) try
{
    // input
    int  nx     = 3;
    int  ny     = 3;
    int  nparts = 2;
    bool full   = false;
    if (argc>1) nx     = atoi(argv[1]);
    if (argc>2) ny     = atoi(argv[2]);
    if (argc>3) nparts = atoi(argv[3]);
    if (argc>4) full   = atoi(argv[4]);

    // mesh
    Array<GemLab::Block> blks(1);
    blks[0].Set (/*NDim*/2, /*Tag*/-1, /*NVert*/4,
                 -1.0,  0.0, 0.0,
                 -2.0,  1.0, 0.0,
                 -3.0,  1.0, 1.0,
                 -4.0,  0.0, 1.0,  -10.0,-20.0,-30.0,-40.0);
    blks[0].SetNx (nx);
    blks[0].SetNy (ny);
    GemLab::SMesh mesh(/*NDim*/2);
    mesh.Generate (blks,/*O2*/false);

    // partitions
    mesh.PartDomain (nparts, full);
    for (size_t i=0; i<mesh.Cells.Size(); ++i) cout << mesh.Cells[i]->PartID << " ";
    cout << endl;

    // output
    mesh.WriteMPY ("mesh04");
    mesh.WriteVTU ("mesh04");

    return 0;
}
GEMLAB_CATCH
